<!--
  功能：功能描述
  作者：邹惜财
  gitee：gitee.com/gujun-zxc
  时间：2020年05月21日 16:09:51
  版本：v1.0
  修改记录：
  修改内容：
  修改人员：
  修改时间：
-->
<template>
<transition name="slide">
 <music-list :title="title" :bgImage="bgImage" :songs="listDetail" ></music-list>
</transition>
</template>

<script>
import {mapGetters} from 'vuex'
import {getSingerDetail} from 'api/singer'
import { code } from 'common/js/config'
import {createSong} from 'common/js/song'
import MusicList from 'components/music-list/music-list'
export default {
  // 组件名称
  name: 'demo',
  // 组件参数 接收来自父组件的数据
  props: {},
  // 组件状态值
  data () {
    return {
      listDetail: [],
      node: null
    }
  },
  /**
  * 组件实例创建完成，属性已绑定，但DOM还未生成，$ el属性还不存在
  */
  created () {
    this._getDetail()
  },
  // 计算属性
  computed: {
    title() {
      let name = ''
      if (this.singer.aliaName) {
        name = this.singer.name + ` (${this.singer.aliaName})`
      } else {
        name = this.singer.name
      }
      return name
    },
    bgImage() {
      console.log(this.singer.avatar)
      return this.singer.avatar
    },
    ...mapGetters([
      'singer'
    ])
  },
  // 组件方法
  methods: {
    _getDetail() {
      if (!this.singer.id) {
        this.$router.push('/singer')
        return
      }
      getSingerDetail(this.singer.id).then(res => {
        if (res.status === code) {
          this.node = res.data.hotSongs
        }
      })
    },
    _normalizeSongs(list) {
      let ret = []
      list.forEach(item => {
        ret.push(createSong(item))
      })
      return ret
    }
  },
  watch: {
    node (val) {
      this.listDetail = this._normalizeSongs(val)
    }
  },
  // 局部注册的组件
  components: {
    MusicList
  }
}
</script>

<style scoped lang="stylus" rel="stylesheet/stylus">
@import '~common/stylus/variable'
.slide-enter-active,.slide-leave-active {
  transition: all 0.3s ease
}
.slide-enter,.slide-leave-to {
  transform: translate3d(100%, 0, 0)
  // opacity: 0;
  }
</style>
